package com.interview02;

import java.util.Arrays;
import java.util.Random;

/**
 * Copyright (C), 2018-2020
 * FileName: Demo2
 * Author:   kongfanyu
 * Date:     2020/12/16 10:25
 * 空间复杂度: O(1) int temp;
 * 时间复杂度: O(n平方)
 */
public class Demo2 {

    public static void main(String[] args) {
        int [] nums = new int[5];
        for (int i = 0; i < 5; i++) {
            nums[i] = new Random().nextInt(100);
        }
        System.out.println("排序之前:"+ Arrays.toString(nums));
        //排序
        for (int i = 0; i < nums.length - 1; i++) {
            for (int j = 0; j < nums.length - 1 - i; j++) {
                if (nums[j] > nums[j + 1]) {
                    int temp = nums[j];
                    nums[j] = nums[j + 1];
                    nums[j + 1] = temp;
                }
            }
        }
        System.out.println("排序之后:"+Arrays.toString(nums));
    }
}
